package com.buba.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import common.R;
import entity.salary.Payrollmodel;
import entity.salary.dto.insertPayModelAndSalaryitemDto;
import entity.salary.vo.selAllPayrollModelVo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.buba.service.PayrollmodelService;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author beisheng
 * @since 2023-03-14
 */
@RestController
@RequestMapping("/payrollmodel")
public class PayrollmodelController {

    @Resource
    private PayrollmodelService payrollmodelService;

    /* *
     * @Author: beisheng
     * @Descriprion: 修改工资单模板或修改工资单模板关联薪资项
     * @Date: 2023/3/22 20:26
     * @Return: common.R
     * @Param: [salaryitemDto]
     */

    @PostMapping("updatePayModelAndSalaryitem")
    public R updatePayModelAndSalaryitem(@RequestBody insertPayModelAndSalaryitemDto salaryitemDto){
        payrollmodelService.updatePayModelAndSalaryitem(salaryitemDto);
        return R.success();
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 添加工资单模板并添加工资单模板关联薪资项
     * @Date: 2023/3/22 18:40
     * @Return: common.R
     * @Param: [insertPayModelAndSalaryitemDto]
     */

    @PostMapping("/insertPayModelAndSalaryitem")
    public R insertPayModelAndSalaryitem(@RequestBody insertPayModelAndSalaryitemDto insertPayModelAndSalaryitemDto){
        payrollmodelService.insertPayModelAndSalaryitem(insertPayModelAndSalaryitemDto);
        return R.success();
    }
    /* *
     * @Author: beisheng
     * @Descriprion: 根据创建时间倒序查询工资单模板
     * @Date: 2023/3/22 10:18
     * @Return: common.R
     * @Param: []
     */

    @GetMapping("/selAllPayrollModel")
    public R selAllPayrollModel(){
        List<selAllPayrollModelVo> selAllPayrollModelVos = payrollmodelService.selAllPayrollModel();
        return R.success(selAllPayrollModelVos);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 更改工资单状态
     * @Date: 2023/3/22 10:38
     * @Return: common.R
     * @Param: [payrollId]
     */

    @GetMapping("/updatePayStatus/{payrollId}")
    public R updatePayStatus(@PathVariable("payrollId") Integer payrollId){
        payrollmodelService.updatePayStatus(payrollId);
        return R.success();
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 逻辑删除工资单模板并逻辑删除工资单模板关联薪资项目
     * @Date: 2023/3/22 13:32
     * @Return: common.R
     * @Param: [payrollId]
     */

    @GetMapping("delPayModelAndSalaryItem/{payrollId}")
    public R delPayModelAndSalaryItem(@PathVariable("payrollId") Integer payrollId){
        payrollmodelService.delPayModelAndSalaryItem(payrollId);
        return R.success();
    }
    /**
     * 功能描述: 新增或更新
     *
     * @param payrollmodel
     * @return
     * @throws
     * @Author: zl
     */
    @PostMapping("/save")
    public R save(@RequestBody Payrollmodel payrollmodel) {
        payrollmodelService.saveOrUpdate(payrollmodel);
        return R.success();
    }

    /**
     * 功能描述: 删除
     *
     * @param id
     * @return
     * @throws
     * @Author: zl
     */
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable Integer id) {
        payrollmodelService.removeById(id);
        return R.success();
    }

    /**
     * 功能描述: 批量删除
     *
     * @param ids
     * @return
     * @throws
     * @Author: zl
     */
    @PostMapping("/deleteBatch")
    public R deleteBatch(@RequestBody List<Integer> ids) {
        payrollmodelService.removeByIds(ids);
        return R.success();
    }

    /**
     * 功能描述: 全查
     *
     * @param
     * @return
     * @throws
     * @Author: zl
     */
    @GetMapping("/findAll")
    public R findAll() {
        return R.success(payrollmodelService.list());
    }

    /**
     * 功能描述: 单查
     *
     * @param id
     * @return
     * @throws
     * @Author: zl
     */
    @GetMapping("/findOne/{id}")
    public R findOne(@PathVariable Integer id) {
        return R.success(payrollmodelService.getById(id));
    }

    /**
     * 功能描述: 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @return
     * @throws
     * @Author: zl
     * @Date:   2022/7/28 19:15
     */
    @GetMapping("/findPage")
    public R findPage(@RequestParam Integer pageNum,
                                 @RequestParam Integer pageSize) {
        QueryWrapper<Payrollmodel> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return R.success(payrollmodelService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

}
